<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询课表</title>
<meta name="renderer" content="webkit">	
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
<meta name="apple-mobile-web-app-status-bar-style" content="black">	
<meta name="apple-mobile-web-app-capable" content="yes">	
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/table.css">
<link rel="stylesheet" href="css/calendar.css">
</head>
<body>
<div class="content-head">悦宝园会员管理系统</div>
<div class="content-main">
	<div class="side-nav" ms-controller="navBar">
		<ul class="nav-item">
			<li><a href="main.html" class="nav-item-front nav-item-add">首页</a></li>
			<li ms-for="el in @navTitleArr">
				<a href="javascript:;" class="nav-item-front">{{el.par}}</a>
				<dl class="nav-item-child">
					<dd ms-for="($index, ex) in el.child"><a ms-attr='{href: el.href[$index]}'>{{ex}}</a></dd>
				</dl>
			</li>
		</ul>
	</div>
	<div class="content bg-gray" ms-controller="main">
		<div class="tab-content">
			<div class="tab-item">
				<div class="sub-main">
					<p class="sub-title"><i>查询课表</i></p>
					<div>
						<div class="week_content">
							<div class="week_title" id="week_title" ids="0">
								<a href="javascript:void(0)" id="prevWeek"></a>
								<h1 id="showDate"></h1>
								<a href="javascript:void(0)" id="nextWeek" class="nextWeek"></a>
							</div>
							<div class="week_box">
								<ul class="clear" id="weekUl"></ul>
							</div>
							<div class="calendar_box clear" id="calendarBox"></div>
						</div>
					</div>
					<div class="schedule-body">
						<div class="schedule-btns">
							<a href="javascript:;" id="subForm" style="background:#fc7169;">删除课表</a>
						</div>
						<table>
							<tbody id="scheduleBody">
								<tr>
									<td valign="top" width="59">时间</td>
									<td valign="top" width="92">老师</td>
									<td valign="top" width="199">姓名</td>
									<td valign="top" width="323">电话</td>
									<td valign="top" width="323">状态</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div> 
</div>
<div class='mask hide' id="mask"></div>
<div class="mask-content passClassContent hide" id="confirmContent" style="width: 450px; height: 130px;">
	<p>确认删除吗？</p>
	<div>
		<a href="javascript:;" id="ok">确认</a>
		<a href="javascript:;" id="cancel">取消</a>
	</div>
</div>

<script src="js/jq.js"></script>
<script src="js/avalon.js"></script>
<script src="js/main.js"></script>
<script src="js/calendar.js"></script>
<script>
(function() {
	var cDate;
	var sData;
	var sObj = {};
	var scheduleData;
	var clickObj;
	var clickTime;
	var students = [];
	var teachers = [];
	var tempStudent = {};

	//初始化日历
	var sDate = baseFunc.getStorageData("schedule");
	var testData = [];
	if (sDate) {
		for (var i = 0; i < sDate.length; i++) {
			if(sDate[i].passStatus) {
				testData.push({date: sDate[i].date, items: [{className:'已核销'}]});
			} else {
				testData.push({date: sDate[i].date, items: [{className:'未核销'}]});
			}
			
		};
	};

	weeklyCalendar(testData,{
		// 点击日期回调
		clickDate: function (date) {
			cDate = date;
			scheduleData = sDate;

			var data,
				htmls = "",
				classNum = 0,
				cc = false;

			$(".delete").remove();
			if(!scheduleData) {
				return;
			}
			sData = "";
			for (var i = 0; i < scheduleData.length; i++) {
				if(scheduleData[i].date == cDate) {
					data = sData = scheduleData[i];
					cc = true;
					break;
				}
			};

			if(!cc) {
				return;
			}

			var sTeacher = "",
				sName,
				sTel,
				sStatus,
				sInfo;
			for (var k = 0; k < data["info"].length; k++) {
				if(data["info"][k].classType == "gym") {
					classNum = 11;
				} else {
					classNum = 9;
				}
				sTeacher = "";
				if(data["info"][k]["teachers"]) {
					$.each(data["info"][k]["teachers"], function(i, elem) {
						if(i == 0) {
							sTeacher = elem["name"];
						} else if (i == 1) {
							sTeacher = sTeacher + "," + elem["name"];
						}
						
					})
				}
				//初始化表格
				htmls = '<tr class="delete"><td rowspan="'+classNum+'" valign="top" width="59"><p>'+data["info"][k]["time"]+'</p><p>'+data["info"][k]["classFullName"]+'</p></td><td data-type="teacher" data-info="'+cDate+','+data["info"][k]["time"]+','+data["info"][k]["className"]+','+data["info"][k]["classFullName"]+'" rowspan="'+classNum+'" valign="top" width="92">'+sTeacher+'</td>';

				for (var q = 0; q < classNum; q++) {
					sName = sTel = sStatus = sInfo = "";
					if(data["info"][k]["students"] && q < data["info"][k]["students"].length) {
						sName = data["info"][k]["students"][q]["name"];
						if(data["info"][k]["students"][q]["tel"]) {
							sTel = data["info"][k]["students"][q]["tel"] ? data["info"][k]["students"][q]["tel"] : "";
						}
						if(data["info"][k]["students"][q]["cc"]) {
							sStatus = data["info"][k]["students"][q]["cc"] ? data["info"][k]["students"][q]["cc"] : "";
						} else {
							//会员首次上课判断
							var firstArr = baseFunc.getStorageData("member", {flag: (data["info"][k]["students"][q])["flag"]})[0]["firstClass"],
								isSame = true;
							
							if(!firstArr) {
								sStatus = "首次上本课程";
							} else {
								for (var x = 0; x < firstArr.length; x++) {
									if(firstArr[x].className == data["info"][k]["className"]) {
										isSame = false;
										break;
									}
								};
								if(isSame) {
									sStatus = "首次上本课程";
								}
							}
						}
					}
					if(data["info"][k]["students"] && q < data["info"][k]["students"].length) {
						sInfo = JSON.stringify(data["info"][k]["students"][q]);
					}
					if(q == 0) {
						htmls += '<td data-type="member" data-info="'+cDate+','+data["info"][k]["time"]+','+data["info"][k]["className"]+','+data["info"][k]["classFullName"]+'" data-moreInfo='+sInfo+' valign="top" width="199">'+sName+'</td><td valign="top" width="323">'+sTel+'</td><td valign="top" width="323">'+sStatus+'</td></tr>';
					} else {
						htmls += '<tr class="delete"><td valign="top" data-type="member" data-info="'+cDate+','+data["info"][k]["time"]+','+data["info"][k]["className"]+','+data["info"][k]["classFullName"]+'" data-moreInfo='+sInfo+'>'+sName+'</td><td valign="top" width="323">'+sTel+'</td><td valign="top" width="323">'+sStatus+'</td></tr>';
					}
				};

				$("#scheduleBody").append(htmls);
			};
		},
		// 点击弹窗回调
		clickDownLoad: function (that) {
			console.log(that)
		}
	}, true);
	$(".current").trigger("click");

	//关闭
	$(".mask").click(function() {
		$("#mask").addClass("hide");
		$("#confirmContent").addClass("hide");
	});
	$("#cancel").click(function() {
		$("#mask").addClass("hide");
		$("#confirmContent").addClass("hide");
	});

	//提交
	$("#subForm").click(function() {
		if(!sData) {
			baseFunc.alert("请选择要删除的课表");
			return;
		}
		if(sData.passStatus) {
			baseFunc.alert("已核销课表不能删除");
			return;
		}
		$("#mask").removeClass("hide");
		$("#confirmContent").removeClass("hide");

		$("#ok").click(function() {

			$("#mask").removeClass("hide");
			$("#confirmContent").removeClass("hide");

			if(sData) {
				baseFunc.deleteStorageData("schedule", {date: cDate});
				$("#mask").addClass("hide");
				$("#confirmContent").addClass("hide");
				baseFunc.alert("删除成功", "green");
				$(".delete").remove();
			}
		});
	});
})();
</script>
</body>
</html>